module WhoCharted
  module ChartFeatures
    module VisibleAxes
      module ClassMethods
        def accepted_arguments
          super + [:visible_axes]
        end

        def argument_dictionary
          super.merge(:visible_axes => \
                      {:key => 'chxt', :method => :gather_visible_axes})
        end
      end

      def self.included base
        base.extend(ClassMethods)
      end

      AXES_DICTIONARY = {
        :bottom => 'x',
        :top => 't',
        :left => 'y',
        :right => 'r'
      }

      def gather_visible_axes
        if visible_axes.class == Array
          visible_axes.map {|k| AXES_DICTIONARY[k]}.join(',')
        elsif visible_axes == :all
          AXES_DICTIONARY.values.join(',')
        else
          AXES_DICTIONARY[visible_axes]
        end
      end
      
      attr_reader :visible_axes

      private

      attr_writer :visible_axes
    end
  end
end
